package com.entities;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Reddit {
	public static final String TAG_OBJECT = "object";
	public static final String TAG_DATA = "data";
	public static final String TAG_CHILDREN = "children";
	public static final String JSON_URL = "http://www.reddit.com/r/DotA2/hot.json";
	public static final String TAG_DOAMIN = "domain";
	public static final String TAG_BANNED_BY = "banned_by";
	public static final String TAG_MEDIA_EMBEDED = "media_embed";
	public static final String TAG_SUBREDDIT = "subreddit";
	public static final String TAG_SELFTEXT_HTML = "selftext_html";
	public static final String TAG_SELFTEXT = "selftext";
	public static final String TAG_LIKES = "likes";
	public static final String TAG_SECURE_MEDIA = "secure_media";
	public static final String TAG_LINK_FLAIR = "link_flair_text";
	public static final String TAG_ID = "id";
	public static final String TAG_GILDED = "gilded";
	public static final String TAG_SERCURE_MEDIA_EMBED = "secure_media_embed";
	public static final String TAG_CLIKED = "clicked";
	public static final String TAG_STICKIED = "stickied";
	public static final String TAG_AUTHOR = "author";
	public static final String TAG_MEDIA = "media";
	public static final String TAG_SCORE = "score";
	public static final String TAG_APROVED_BY = "approved_by";
	public static final String TAG_OVER_18 = "over_18";
	public static final String TAG_HIDDEN = "hidden";
	public static final String TAG_THUMBNAIL = "thumbnail";
	public static final String TAG_SUBREDDIT_ID = "subreddit_id";
	public static final String TAG_EDITED = "edited";
	public static final String TAG_LINK_FLAIR_CSS = "link_flair_css_class";
	public static final String TAG_AUTHOR_FLAIR_CSS = "author_flair_css_class";
	public static final String TAG_DOWNS = "downs";
	public static final String TAG_SAVED = "saved";
	public static final String TAG_IS_SELF = "is_self";
	public static final String TAG_PERMALINK = "permalink";
	public static final String TAG_NAME = "name";
	public static final String TAG_CREATED = "created";
	public static final String TAG_URL = "url";
	public static final String TAG_AUTHOR_FLAR_TEX = "author_flair_text";
	public static final String TAG_TITLE = "title";
	public static final String TAG_CREATED_UTC = "created_utc";
	public static final String TAG_UPS = "ups";
	public static final String TAG_NUM_COMMENTS = "num_comments";
	public static final String TAG_VISITED = "visited";
	public static final String TAG_NUM_REPORTS = "num_reports";
	public static final String TAG_DISTINGUISHED = "distinguished";
	
	public static List<Reddit> redditList;
	
	private String domain;
	private String banned_by;
	private String media_embed;
	private String subreddit;
	private String selftext_html;
	private String selftext;
	private String likes;
	private String secure_media;
	private String link_flair_text;
	private String id;
	private int gilded;
	private String secure_media_embed;
	private boolean clicked;
	private boolean stickied;
	private String author;
	private String media;
	private int score;
	private String approved_by;
	private boolean over_18;
	private boolean hidden;
	private String thumbnail;
	private String subreddit_id;
	private Long edited;
	private String link_flair_css_class;
	private String author_flair_css_class;
	private int downs;
	private boolean saved;
	private boolean is_self;
	private String permalink;
	private String name;
	private Long created;
	private String url;
	private String author_flair_text;;
	private String title;
	private Long created_utc;
	private int ups;
	private int num_comments;
	private boolean visited;
	private String num_reports;
	private String distinguished;
	
	public String getDomain() {
		return domain;
	}
	public String getBanned_by() {
		return banned_by;
	}
	public String getMedia_embed() {
		return media_embed;
	}
	public String getSubreddit() {
		return subreddit;
	}
	public String getSelftext_html() {
		return selftext_html;
	}
	public String getSelftext() {
		return selftext;
	}
	public String getLikes() {
		return likes;
	}
	public String getSecure_media() {
		return secure_media;
	}
	public String getLink_flair_text() {
		return link_flair_text;
	}
	public String getId() {
		return id;
	}
	public int getGilded() {
		return gilded;
	}
	public String getSecure_media_embed() {
		return secure_media_embed;
	}
	public boolean isClicked() {
		return clicked;
	}
	public boolean isStickied() {
		return stickied;
	}
	public String getAuthor() {
		return author;
	}
	public String getMedia() {
		return media;
	}
	public int getScore() {
		return score;
	}
	public String getApproved_by() {
		return approved_by;
	}
	public boolean isOver_18() {
		return over_18;
	}
	public boolean isHidden() {
		return hidden;
	}
	public String getThumbnail() {
		return thumbnail;
	}
	public String getSubreddit_id() {
		return subreddit_id;
	}
	public Long getEdited() {
		return edited;
	}
	public String getLink_flair_css_class() {
		return link_flair_css_class;
	}
	public String getAuthor_flair_css_class() {
		return author_flair_css_class;
	}
	public int getDowns() {
		return downs;
	}
	public boolean isSaved() {
		return saved;
	}
	public boolean getIs_self() {
		return is_self;
	}
	public String getPermalink() {
		return permalink;
	}
	public String getName() {
		return name;
	}
	public Long getCreated() {
		return created;
	}
	public String getUrl() {
		return url;
	}
	public String getAuthor_flair_text() {
		return author_flair_text;
	}
	public String getTitle() {
		return title;
	}
	public Long getCreated_utc() {
		return created_utc;
	}
	public int getUps() {
		return ups;
	}
	public int getNum_comments() {
		return num_comments;
	}
	public boolean isVisited() {
		return visited;
	}
	public String getNum_reports() {
		return num_reports;
	}
	public String getDistinguished() {
		return distinguished;
	}
	
	public Reddit(String domain, String banned_by, String media_embed,
			String subreddit, String selftext_html, String selftext,
			String likes, String secure_media, String link_flair_text,
			String id, int gilded, String secure_media_embed, boolean clicked,
			boolean stickied, String author, String media, int score,
			String approved_by, boolean over_18, boolean hidden,
			String thumbnail, String subreddit_id, Long edited,
			String link_flair_css_class, String author_flair_css_class,
			int downs, boolean saved, boolean is_self, String permalink,
			String name, Long created, String url, String author_flair_text,
			String title, Long created_utc, int ups, int num_comments,
			boolean visited, String num_reports, String distinguished) {
		super();
		this.domain = domain;
		this.banned_by = banned_by;
		this.media_embed = media_embed;
		this.subreddit = subreddit;
		this.selftext_html = selftext_html;
		this.selftext = selftext;
		this.likes = likes;
		this.secure_media = secure_media;
		this.link_flair_text = link_flair_text;
		this.id = id;
		this.gilded = gilded;
		this.secure_media_embed = secure_media_embed;
		this.clicked = clicked;
		this.stickied = stickied;
		this.author = author;
		this.media = media;
		this.score = score;
		this.approved_by = approved_by;
		this.over_18 = over_18;
		this.hidden = hidden;
		this.thumbnail = thumbnail;
		this.subreddit_id = subreddit_id;
		this.edited = edited;
		this.link_flair_css_class = link_flair_css_class;
		this.author_flair_css_class = author_flair_css_class;
		this.downs = downs;
		this.saved = saved;
		this.is_self = is_self;
		this.permalink = permalink;
		this.name = name;
		this.created = created;
		this.url = url;
		this.author_flair_text = author_flair_text;
		this.title = title;
		this.created_utc = created_utc;
		this.ups = ups;
		this.num_comments = num_comments;
		this.visited = visited;
		this.num_reports = num_reports;
		this.distinguished = distinguished;
	}
	public Reddit(JSONObject jsonobj) throws JSONException{
		String domain;
		String empty = "";
		int nil = -1;
		JSONObject json = jsonobj.getJSONObject(TAG_DATA);
		try {
			domain = json.getString(TAG_DOAMIN);
		} catch (JSONException e) {
			domain = empty;
		}
		String banned_by;
		try {
			banned_by = json.getString(TAG_BANNED_BY);
		} catch (JSONException e) {
			banned_by = empty;
		}
		String media_embed;
		try {
			media_embed = json.getString(TAG_MEDIA_EMBEDED);
		} catch (JSONException e) {
			media_embed = empty;
		}
		String subreddit;
		try {
			subreddit = json.getString(TAG_SUBREDDIT);
		} catch (JSONException e) {
			subreddit = empty;
		}
		String selftext_html;
		try {
			selftext_html = json.getString(TAG_SELFTEXT_HTML);
		} catch (JSONException e) {
			selftext_html = empty;
		}
		String selftext;
		try {
			selftext = json.getString(TAG_SELFTEXT);
		} catch (JSONException e) {
			selftext = empty;
		}
		String likes;
		try {
			likes = json.getString(TAG_LIKES);
		} catch (JSONException e) {
			likes = empty;
		}
		String secure_media;
		try {
			secure_media = json.getString(TAG_SECURE_MEDIA);
		} catch (JSONException e) {
			secure_media = empty;
		}
		String link_flair_text;
		try {
			link_flair_text = json.getString(TAG_LINK_FLAIR);
		} catch (JSONException e) {
			link_flair_text = empty;
		}
		String id;
		try {
			id = json.getString(TAG_ID);
		} catch (JSONException e1) {
			id = empty;
		}
		int gilded;
		try {
			gilded = json.getInt(TAG_GILDED);
		} catch (JSONException e) {
			gilded =nil;
		}
		String secure_media_embed;
		try {
			secure_media_embed = json.getString(TAG_SERCURE_MEDIA_EMBED);
		} catch (JSONException e) {
			secure_media_embed = empty;
		}
		boolean clicked;
		try {
			clicked = json.getBoolean(TAG_CLIKED);
		} catch (JSONException e) {
			clicked = false;
		}
		boolean stickied;
		try {
			stickied = json.getBoolean(TAG_STICKIED);
		} catch (JSONException e) {
			stickied = false;
		}
		String author;
		try {
			author = json.getString(TAG_AUTHOR);
		} catch (JSONException e) {
			author = empty;
		}
		String media;
		try {
			media = json.getString(TAG_MEDIA);
		} catch (JSONException e) {
			media = empty;
		}
		int score;
		try {
			score = json.getInt(TAG_SCORE);
		} catch (JSONException e) {
			score = nil;
		}
		String approved_by;
		try {
			approved_by = json.getString(TAG_APROVED_BY);
		} catch (JSONException e) {
			approved_by = empty;
		}
		boolean over_18;
		try {
			over_18 = json.getBoolean(TAG_OVER_18);
		} catch (JSONException e) {
			over_18 = false;
		}
		boolean hidden;
		try {
			hidden = json.getBoolean(TAG_HIDDEN);
		} catch (JSONException e) {
			hidden = false;
		}
		String thumbnail;
		try {
			thumbnail = json.getString(TAG_THUMBNAIL);
		} catch (JSONException e) {
			thumbnail = empty;
		}
		String subreddit_id;
		try {
			subreddit_id = json.getString(TAG_SUBREDDIT_ID);
		} catch (JSONException e1) {
			subreddit_id = empty;
		}
		Long edited;
		try {
			edited = Long.valueOf(json.getString(TAG_EDITED));
		} catch (NumberFormatException e) {
			edited = Long.valueOf(nil);
		} catch (JSONException e) {
			edited = Long.valueOf(nil);
		}
		String link_flair_css_class;
		try {
			link_flair_css_class = json.getString(TAG_LINK_FLAIR_CSS);
		} catch (JSONException e) {
			link_flair_css_class = empty;
		}
		String author_flair_css_class;
		try {
			author_flair_css_class = json.getString(TAG_AUTHOR_FLAIR_CSS);
		} catch (JSONException e1) {
			author_flair_css_class = empty;
		}
		int downs;
		try {
			downs = json.getInt(TAG_DOWNS);
		} catch (JSONException e) {
			downs = nil;
		}
		boolean saved;
		try {
			saved = json.getBoolean(TAG_SAVED);
		} catch (JSONException e) {
			saved = false;
		}
		boolean is_self;
		try {
			is_self = json.getBoolean(TAG_IS_SELF);
		} catch (JSONException e) {
			is_self = false;
		}
		String permalink;
		try {
			permalink = json.getString(TAG_PERMALINK);
		} catch (JSONException e) {
			permalink = empty;
		}
		String name;
		try {
			name = json.getString(TAG_NAME);
		} catch (JSONException e) {
			name = empty;
		}
		Long created;
		try {
			created = Long.valueOf((long) json.getDouble(TAG_CREATED));
		} catch (NumberFormatException e) {
			created = Long.valueOf(nil);
		} catch (JSONException e) {
			created = Long.valueOf(nil);
		}
		String url;
		try {
			url = json.getString(TAG_URL);
		} catch (JSONException e) {
			url = empty;
		}
		String author_flair_text;
		try {
			author_flair_text = json.getString(TAG_AUTHOR_FLAR_TEX);
		} catch (JSONException e) {
			author_flair_text = empty;
		}
		String title;
		try {
			title = json.getString(TAG_TITLE);
		} catch (JSONException e) {
			title = empty;
		}
		Long created_utc;
		try {
			created_utc = Long.valueOf((long) json.getDouble(TAG_CREATED_UTC));
		} catch (NumberFormatException e1) {
			created_utc = Long.valueOf(nil);
		} catch (JSONException e1) {
			created_utc = Long.valueOf(nil);
		}
		int ups;
		try {
			ups = json.getInt(TAG_UPS);
		} catch (JSONException e) {
			ups = nil;
		}
		int num_comments;
		try {
			num_comments = json.getInt(TAG_NUM_COMMENTS);
		} catch (JSONException e) {
			num_comments = nil;
		}
		boolean visited;
		try {
			visited = json.getBoolean(TAG_VISITED);
		} catch (JSONException e1) {
			visited = false;
		}
		String num_reports;
		try {
			num_reports = json.getString(TAG_NUM_REPORTS);
		} catch (JSONException e) {
			num_reports = empty;
		}
		String distinguished;
		try {
			distinguished = json.getString(TAG_DISTINGUISHED);
		} catch (JSONException e) {
			distinguished = empty;
		}
		
		this.domain = domain;
		this.banned_by = banned_by;
		this.media_embed = media_embed;
		this.subreddit = subreddit;
		this.selftext_html = selftext_html;
		this.selftext = selftext;
		this.likes = likes;
		this.secure_media = secure_media;
		this.link_flair_text = link_flair_text;
		this.id = id;
		this.gilded = gilded;
		this.secure_media_embed = secure_media_embed;
		this.clicked = clicked;
		this.stickied = stickied;
		this.author = author;
		this.media = media;
		this.score = score;
		this.approved_by = approved_by;
		this.over_18 = over_18;
		this.hidden = hidden;
		this.thumbnail = thumbnail;
		this.subreddit_id = subreddit_id;
		this.edited = edited;
		this.link_flair_css_class = link_flair_css_class;
		this.author_flair_css_class = author_flair_css_class;
		this.downs = downs;
		this.saved = saved;
		this.is_self = is_self;
		this.permalink = permalink;
		this.name = name;
		this.created = created;
		this.url = url;
		this.author_flair_text = author_flair_text;
		this.title = title;
		this.created_utc = created_utc;
		this.ups = ups;
		this.num_comments = num_comments;
		this.visited = visited;
		this.num_reports = num_reports;
		this.distinguished = distinguished;
		
	}
	
	public static List<Reddit> getWhatIsHot(JSONObject json){
		List<Reddit> list = new ArrayList<Reddit>();
		try {
			JSONArray ja = json.getJSONObject(TAG_DATA).getJSONArray(TAG_CHILDREN);
			for(int cont = 0; cont < ja.length();cont++){
				list.add(new Reddit(ja.getJSONObject(cont)));
				
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		redditList = list;
		return redditList;
	}
}
